package person.xjl.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import person.xjl.dao.StudentMapper;
import person.xjl.domain.Student;
import person.xjl.service.StudentService;

import java.util.List;
//默认的service对象的名字叫 studentServiceImpl ：类或者接口的首写字母变小写
//Spring 容器创建一个service类型的bean，将来给controller层调用
@Service
public class StudentServiceImpl implements StudentService {
    //定义将要引用的DAO对象---studentMapper,对象的名字：类或者接口的首写字母变小写
    //自动注入对象，来自于Spring 容器
    @Autowired
    private StudentMapper studentMapper;
    //实现显示所有学生
    @Override
    public List<Student> list() {

        return studentMapper.list();
    }

    @Override
    public int add(Student student) {
        return studentMapper.insert(student);
    }

    @Override
    public int delete(int id) {
        return studentMapper.deleteByPrimaryKey(id);
    }

    @Override
    public Student select(int id) {
        return studentMapper.selectByPrimaryKey(id);
    }

    @Override
    public int update(Student student) {
        return studentMapper.updateByPrimaryKey(student);
    }

    @Override
    public Student login(String name, String password) {
        return studentMapper.login(name,password);
    }
}
